﻿@if (ChildContent != null)
{
    @if (menu.Children.Count > 0)
    {
        <SubMenu Key="@menu.Name" TitleTemplate=@GetRenderFragment(menu.Title,menu.Icon) ChildContent="ChildContent">
        </SubMenu>
    }
    else
    {
        <MenuItem RouterLink="@menu.PathWithId" RouterMatch="NavLinkMatch.All" Key="@menu.Name" Title="@menu.Title" Icon="@menu.Icon" OnClick="()=>menuOnClick(menu)">
        </MenuItem>
    }

}

@inject ReuseTabsService ReuseTabsService

@code {

    [Parameter]
    public SysMenu menu { get; set; }

    [Parameter]
    public RenderFragment ChildContent { get; set; }

    RenderFragment GetRenderFragment(string title, string iceType = "setting")
    {
        return
    @<span>
        <Icon Type=@iceType Theme="IconThemeType.Outline"></Icon>
        <span>@title</span>
    </span>
    ;
    }

    private void menuOnClick(SysMenu s)
    {

        var _this = this;
        var _s = s;
        Task.Run(() =>
        {
            _this.InvokeAsync(async () =>
                {
                    await Task.Delay(300);
                    ReuseTabsService.CreateTab(_s.PathWithId);
                    // ReuseTabsService.Update();
                });

        });
    }
}